// 对于给定的整数 n 从小到大依次输出它的全部质因子。

const getAllPrimeNumber = (n) => {
	const primeArr = [];

	if (n < 2) {
		return primeArr;
	}

	// 处理所有偶数
	while (n % 2 === 0) {
		primeArr.push(2);

		n = n / 2;
	}

	// 处理所有奇数

	for (let i = 3; i * i <= n; i += 2) {
		while (n % i === 0) {
			primeArr.push(i);
			n = n / i;
		}
	}

	if (n > 2) {
		primeArr.push(n);
	}

	console.log(primeArr.join(" "));
};

// getAllPrimeNumber(18);

// 四舍五入后取整数

function testNum(n) {
	const a = Math.floor(n);

	const b = n - a;

	if (b >= 0.5) {
		console.log(Math.ceil(n));
	} else {
		console.log(a);
	}
}

// 相同索引求和运算

const getSameKeyAdd = (arr = []) => {
	if (arr.length === 0) {
		return;
	}

	const obj = {};

	for (const item of arr) {
		const { index, value } = item;

		if (typeof obj[index] !== "undefined") {
			obj[index] += value;
		} else {
			obj[index] = value;
		}
	}

	for (const key in obj) {
		console.log(key, obj[key]);
	}
};

// getSameKeyAdd([{index: 0, value: 1}, {index: 0, value: 3}, {index: 1, value: 5}, {index: 3, value: 9}])

const queueDemo = (str = "") => {
	const len = str.length;
	if (len == 0) {
		return;
	}

	const arr = [];

	for (let index = len - 1; index >= 0; index--) {
		const char = str[index];
		// console.log(char);
		if (arr.length == 0) {
			arr.push(char);
		} else {
			const b = arr.find((e) => e == char);
			if (!b) {
				arr.push(char);
			}
		}
	}

	console.log(arr.join(""));
};

// queueDemo("4312144");

const middleDemo = () => {
	// const reg = /^([ASDW]\d+)+$/;
	const reg = /^[ASDW](\d{1,2})$/;

  const reg1 = /^[ADWS](\d{1,2})$/;

  const str = "A30"

	// const flag = reg.test("A30S40");

	// console.log(flag);

  const arr = str.match(reg1)

  console.log(arr)

  
};

middleDemo();
